package com.mvu.banana.guest.client.gen;
import static com.mvu.banana.common.validation.Validator.*;
import com.mvu.banana.domain.client.Gender;
import com.mvu.banana.common.widget.DayBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.mvu.banana.guest.client.SignUpForm;
import com.google.gwt.user.client.ui.TextBox;
import java.util.Date;
import com.mvu.banana.common.client.ValueDTO;
import com.mvu.banana.common.widget.HintListener;
import com.mvu.banana.common.widget.EnumBox;


public class SignUpFormDTO extends ValueDTO<SignUpForm>{

  public String name;

  public String email;

  public String password;

  public Gender gender;

  public Date birthDay;

  public void SignUpFormDTO(){
  }

  @Override
  public void prepare(SignUpForm p0){
    if(p0.name == null){
      p0.name = new TextBox();
    };
    p0.name.setName("name");
    p0.name.setTitle("SignUpForm_name");
    p0.name.addFocusHandler(HintListener.get());
    p0.name.addBlurHandler(HintListener.get());
    if(p0.email == null){
      p0.email = new TextBox();
    };
    p0.email.setName("email");
    p0.email.setTitle("SignUpForm_email");
    p0.email.addFocusHandler(HintListener.get());
    p0.email.addBlurHandler(HintListener.get());
    if(p0.password == null){
      p0.password = new PasswordTextBox();
    };
    p0.password.setName("password");
    p0.password.setTitle("SignUpForm_password");
    p0.password.addFocusHandler(HintListener.get());
    p0.password.addBlurHandler(HintListener.get());
    if(p0.gender == null){
      p0.gender = new EnumBox(Gender.class);
    };
    p0.gender.setName("gender");
    if(p0.birthDay == null){
      p0.birthDay = new DayBox();
    };
    p0.birthDay.setName("birthDay");
  }

  public boolean validate(SignUpForm p0){
    boolean isValid = true;
    boolean nameIsValid = isLength(name, 2, 30) && isNotNull(name);
    p0.highlight(p0.name, nameIsValid);
    isValid &= nameIsValid;
    boolean emailIsValid = isNotNull(email) && isEmail(email);
    p0.highlight(p0.email, emailIsValid);
    isValid &= emailIsValid;
    boolean passwordIsValid = isLength(password, 2, 100) && isNotNull(password);
    p0.highlight(p0.password, passwordIsValid);
    isValid &= passwordIsValid;
    boolean genderIsValid = isNotNull(gender);
    p0.highlight(p0.gender, genderIsValid);
    isValid &= genderIsValid;
    boolean birthDayIsValid = isNotNull(birthDay);
    p0.highlight(p0.birthDay, birthDayIsValid);
    isValid &= birthDayIsValid;
    return isValid;
  }

  @Override
  public void copy(SignUpForm p0){
    this.name = p0.name.getValue();
    this.email = p0.email.getValue();
    this.password = p0.password.getValue();
    this.gender = p0.gender.getValue();
    this.birthDay = p0.birthDay.getValue();
  }
}